#!/bin/bash
#
# Copyright 2015-2020, Guilherme Jardim
# Copyright 2022-2025, Dan Landon
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 2,
# as published by the Free Software Foundation.
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#

# Path to the preclear directory
preclear_dir="/tmp/.preclear"

# Find directories in $preclear_dir and iterate over them
find "$preclear_dir" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | while read -r disk; do

    if [ ! -e "$preclear_dir/$disk/pause" ] && [ -e "/tmp/preclear/preclear_stat_$disk" ]; then
		echo "Pausing preclear of disk '$disk'" | logger -t preclear.disk
		touch "$preclear_dir/$disk/pause"
	fi
done
